home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
docume1a
/
frmrepla
(
.txt
)
< prev
next >
Wrap
Visual Basic Form
|
1999-07-18
|
8KB
|
251 lines
VERSION 5.00
Begin VB.Form frmReplace
BorderStyle = 1 'Fixed Single
Caption = " Replace Text"
ClientHeight = 2835
ClientLeft = 45
ClientTop = 330
ClientWidth = 4920
ClipControls = 0 'False
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2835
ScaleWidth = 4920
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
WhatsThisButton = -1 'True
WhatsThisHelp = -1 'True
Begin VB.CommandButton cmdClose
Cancel = -1 'True
Caption = "&Close"
Height = 375
Left = 3360
TabIndex = 10
Top = 1920
Width = 1215
End
Begin VB.CommandButton cmdReplaceAll
Caption = "Replace &All"
Enabled = 0 'False
Height = 375
Left = 3360
TabIndex = 9
Top = 1320
Width = 1215
End
Begin VB.CommandButton cmdReplace
Caption = "&Replace"
Enabled = 0 'False
Height = 375
Left = 3360
TabIndex = 8
Top = 720
Width = 1215
End
Begin VB.CommandButton cmdNext
Caption = "Find &Next"
Height = 375
Left = 3360
TabIndex = 7
Top = 120
Width = 1215
End
Begin VB.CommandButton cmdFind
Caption = "&Find"
Height = 375
Left = 360
TabIndex = 6
Top = 2280
Visible = 0 'False
Width = 1215
End
Begin VB.CheckBox Check2
Caption = "Case &Sensitive"
Height = 375
Left = 360
TabIndex = 5
Top = 1560
Width = 1455
End
Begin VB.CheckBox Check1
Caption = "&Whole Word Only"
Height = 375
Left = 360
TabIndex = 4
Top = 1200
Width = 1575
End
Begin VB.TextBox Text2
Height = 285
Left = 1440
TabIndex = 3
Top = 720
Width = 1815
End
Begin VB.TextBox Text1
Height = 285
Left = 1440
TabIndex = 2
Top = 120
Width = 1815
End
Begin VB.Frame Frame1
Height = 975
Left = 240
TabIndex = 11
Top = 1080
Width = 1935
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Replace With:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 120
TabIndex = 1
Top = 720
Width = 1260
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Find What:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 120
TabIndex = 0
Top = 120
Width = 945
End
Attribute VB_Name = "frmReplace"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim OriginalParenthWnd As Long
Dim Position As Long
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdFind_Click()
Dim FindFlags As Long
On Error GoTo ErrorTrap
Position = 0
FindFlags = Check1.Value * 2 + Check2.Value * 4
Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
If Position >= 0 Then
r = Text1.Text
frmOpenDoc.SetFocus
cmdReplace.Enabled = True
cmdReplaceAll.Enabled = True
Text2.Enabled = True
Text1.Text = r
MsgBox "Document has finished searching the document." & Chr(13) & Chr(13) & Chr(34) & Text1.Text & Chr(34) & " was not found!"
cmdReplace.Enabled = False
cmdReplaceAll.Enabled = False
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
Exit Sub
ErrorTrap:
Call ErrorTrap
End Sub
Private Sub cmdNext_Click()
Dim FindFlags As Long
On Error GoTo ErrorTrap
FindFlags = Check1.Value * 2 + Check2.Value * 4
Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
If Position > 0 Then
p = Text1.Text
frmOpenDoc.SetFocus
cmdReplace.Enabled = True
cmdReplaceAll.Enabled = True
Text2.Enabled = True
Text1.Text = p
MsgBox "Document has finished searching the document." & Chr(13) & Chr(13) & Chr(34) & Text1.Text & Chr(34) & " was not found!"
cmdReplace.Enabled = False
cmdReplaceAll.Enabled = False
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
Exit Sub
ErrorTrap:
Call ErrorTrap
End Sub
Private Sub cmdReplace_Click()
Dim FindFlags As Integer
On Error GoTo ErrorTrap
frmOpenDoc.RichTextBox1.SelText = Text2.Text
FindFlags = Check1.Value * 2 + Check2.Value * 4
Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
If Position > 0 Then
frmFind.Hide
frmOpenDoc.SetFocus
boolsave = True
SaveEnabled
MsgBox "Document has finished replacing " & Chr(34) & Text1.Text & Chr(34) & " with " & Chr(34) & Text2.Text & Chr(34)
cmdReplace.Enabled = False
cmdReplaceAll.Enabled = False
Text1.SetFocus
End If
Exit Sub
ErrorTrap:
Call ErrorTrap
End Sub
Private Sub cmdReplaceAll_Click()
On Error GoTo ErrorTrap
FindFlags = Check1.Value * 2 + Check2.Value * 4
frmOpenDoc.RichTextBox1.SelText = Text2.Text
Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
While Position > 0
Screen.MousePointer = 11
MDIForm1.StatusBar1.Panels(1).Text = "Replacing text, please wait..."
frmOpenDoc.RichTextBox1.SelText = Text2.Text
Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
Screen.MousePointer = 0
cmdReplace.Enabled = False
cmdReplaceAll.Enabled = False
MsgBox "Document has finished replacing " & Chr(34) & Text1.Text & Chr(34) & " with " & Chr(34) & Text2.Text & Chr(34)
boolsave = True
Text1.SetFocus
SaveEnabled
MDIForm1.StatusBar1.Panels(1).Text = MDIForm1.CommonDialog1.FileName
Exit Sub
ErrorTrap:
Call ErrorTrap
End Sub
Private Sub Form_Load()
frmOpenDochwnd = SetWindowLong(Me.hwnd, GWW_HWNDPARENT, frmOpenDoc.hwnd)
Width = 0.4 * Screen.Width
Height = 0.32 * Screen.Height
Left = (Screen.Width - Width) / 2
Top = (Screen.Height - Height) / 2
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim r As Long
r = SetWindowLong(Me.hwnd, GWW_HWNDPARENT, OriginalParenthWnd)
End Sub
Private Sub Text2_Change()
cmdReplace.Enabled = (Len(Text2.Text) > 0)
cmdReplaceAll.Enabled = (Len(Text2.Text) > 0)
End Sub